package com.umakr.demo.controller;

import com.umakr.demo.model.Kecheng;
import com.umakr.demo.service.KechengService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/19.
 */
@Controller
@RequestMapping("/KechengController")
public class KechengController {
    @Autowired
    KechengService kechengService;

    @RequestMapping("/showKecheng")
    public String showKecheng(){
        System.out.println("run");
        return "StudentManage/kecheng";
    }

    @RequestMapping("/kechengDate")
    @ResponseBody
    public List kechengDate(){
        System.out.println("run");
        List<Kecheng> list = kechengService.showAll();
        return list;
    }

    @RequestMapping("/saveKecheng")
    @ResponseBody
    public void saveKecheng(Long kid,String kname){
        System.out.println("run");
        Kecheng kecheng = new Kecheng(kid,kname);
        kechengService.saveKecheng(kecheng);
    }

    @RequestMapping("/deleteKecheng")
    @ResponseBody
    public List<Kecheng> deleteKecheng(Long kid,String kname){
        Kecheng kecheng = new Kecheng(kid,kname);
        kechengService.deleteKecheng(kecheng);
        List<Kecheng> list = kechengService.showAll();
        return list;
    }


    @RequestMapping("/updateKecheng")
    @ResponseBody
    public  List<Kecheng> updateKecheng(Long kid,String kname){
        Kecheng kecheng = new Kecheng(kid,kname);
        kechengService.updateKecheng(kecheng);
        List<Kecheng> list = kechengService.showAll();
        return  list;
    }
}
